﻿using System;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using AnyOffice.Components;
using AnyOffice.DAL;
namespace AnyOffice.general.system.workflow.flow_form
{
    public partial class form_cool : ModulePage
    {
        public int intFormId;
        public string strFormModel = string.Empty;


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                Match match;
                this.intFormId = (Request.QueryString["form_id"] == null) ? 0 : int.Parse(Request.QueryString["form_id"].ToString());
                string input = string.Empty;
                DataTable table = new FlowFormTypeDao().SelectByFormId(base.Conn, this.intFormId);
                if ((table.Rows.Count > 0) && (table.Rows[0]["FormModel"] != DBNull.Value))
                {
                    input = table.Rows[0]["FormModel"].ToString();
                }
                input = input.Replace("\r", "").Replace("\n", "");
                int startIndex = 0;
                StringBuilder builder = new StringBuilder();
                string pattern = "<(?<Tag>IMG)[^>]*?class=DATE[^>]*?\\stitle=(?:(?<Title>[^\\s\"'>]+)|(?:\"(?<Title>.*?)\")|(?:\\'(?<Title>.*)\\'))[^>]*?\\ssrc=(?:(?<src>[^\\s\"'>]+)|(?<src>\\w+)|\"(?<src>.*?)\"|\\'(?<src>.*?)\\')[^>]*?>";
                Regex regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                for (match = regex.Match(input); match.Success; match = match.NextMatch())
                {
                    if (match.Groups["src"].Success)
                    {
                        builder.Append(input.Substring(startIndex, match.Groups["src"].Index - startIndex));
                        builder.Append("/images/form/calendar.gif");
                        startIndex = match.Groups["src"].Index + match.Groups["src"].Length;
                    }
                }
                builder.Append(input.Substring(startIndex));
                input = builder.ToString();
                startIndex = 0;
                builder = new StringBuilder();
                pattern = "<(?<Tag>IMG)[^>]*?class=LIST_VIEW[^>]*?\\stitle=(?:(?<Title>[^\\s\"'>]+)|(?:\"(?<Title>.*?)\")|(?:\\'(?<Title>.*)\\'))[^>]*?\\ssrc=(?:(?<src>[^\\s\"'>]+)|(?<src>\\w+)|\"(?<src>.*?)\"|\\'(?<src>.*?)\\')[^>]*?>";
                regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                for (match = regex.Match(input); match.Success; match = match.NextMatch())
                {
                    if (match.Groups["src"].Success)
                    {
                        builder.Append(input.Substring(startIndex, match.Groups["src"].Index - startIndex));
                        builder.Append("/images/form/listview.gif");
                        startIndex = match.Groups["src"].Index + match.Groups["src"].Length;
                    }
                }
                builder.Append(input.Substring(startIndex));
                input = builder.ToString().Replace(@"\", @"\\").Replace("\"", "\\\"");
                this.strFormModel = input;
            }
        }
       
    }
}

